package com.atguigu.tingshu.user.pattern.facotry;

import com.atguigu.tingshu.common.execption.GuiguException;
import com.atguigu.tingshu.user.pattern.UserPaidStrategy;
import com.atguigu.tingshu.user.pattern.impl.AlbumUserPaidStrategy;
import com.atguigu.tingshu.user.pattern.impl.TrackUserPaidStrategy;
import com.atguigu.tingshu.user.pattern.impl.VIPUserPaidStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: atguigu
 * @create: 2024-03-09 11:41
 */
@Slf4j
@Component
public class StrategyFactory {

    /**
     * 将目前所有策略实现类对象进行封装
     * Map中Key：实现类对象BeanID 就是不同策略实现类自定义beanID：购买项目类型
     * Map中Value：购买行为实现类对象
     */
    @Autowired
    private Map<String, UserPaidStrategy> userPaidStrategyMap;


    /**
     * 提供根据购买项目类型获取具体策略实现类对象
     *
     * @param orderItemType
     * @return
     */
    public UserPaidStrategy getStrategy(String orderItemType) {
        if (userPaidStrategyMap.containsKey(orderItemType)) {
            return userPaidStrategyMap.get(orderItemType);
        }
        throw new GuiguException(400, "购买项目类型不支持！");
    }

}
